package exception

import (
	"fmt"
)

// Exception 自定义异常结构定义
type Exception struct {
	// 错误编号
	Code int
	// 错误名称
	Name string
	// 自带消息
	Message string
}

// NewException create a new exception instance
func NewException(code int, name, message string, a ...interface{}) *Exception {
	return &Exception{
		Code:    code,
		Name:    name,
		Message: fmt.Sprintf(message, a...),
	}
}

// NewExceptionWithDefine create a new exception instance with predefined
func NewExceptionWithDefine(define Exception, a ...interface{}) *Exception {
	return &Exception{
		Code:    define.Code,
		Name:    define.Name,
		Message: fmt.Sprintf(define.Message, a...),
	}
}
